package com.oyjd;

import java.io.File;
import java.text.MessageFormat;


public class DownMovie {
	public static String hot_sql = "insert into T_HOT_SOURCE (DOWN_COUNT, SOU_ID, SOU_TYPE, ID) values ({0}, ''{1}'', ''{2}'', ''{3}'');";
	public static String order_sql = "insert into T_MOVIE_TYPE_ORDER (ORDER_KEY, MOVIE_ID, TYPE, ID) values ({0}, ''{1}'', ''{2}'', ''{3}'');";

	public static String souPath = "N:/SL/trunk/movie/";
	public static String sqlPath = "N:/SL/trunk/script/movie.sql";

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		File file = new File(souPath);
		File[] ff = file.listFiles();
		int count = 8;
		StringBuffer sb = new StringBuffer("use sldb;\r\n\r\n");
		StringBuffer sb1 = new StringBuffer("\r\n#==============================\r\n");
		StringBuffer sb2 = new StringBuffer("\r\n#==============================\r\n");
		int np = 1;
		for (File f : ff) {

			if (f.isFile()&&f.getName().endsWith("mp4")) {
				String souId = FileOP.getUUID();
				int p = f.getName().lastIndexOf(".");
				String ex = f.getName().substring(p + 1);
				String desc = f.getName().substring(0, p);
				String newName = FileOP.getNewHashName(f.getName(), "sl_movie");
				String picName = newName.substring(0,newName.lastIndexOf(".")) + ".jpg";
				String sql = "insert into T_MOVIE (MOVIE_ID, DESCRIPTION, FORMAT, ICON_PATH, NAME, SOU_PATH, SPACE_SIZE, CREATOR, CREATE_TIME, LAST_EDITOR, LAST_UPDATE_TIME, STATUS) values ('" + souId + "', '" + desc + "', '" + ex + "', '" + picName + "', '" + desc + "', '" + newName + "', " + f.length() + ", 'admin', now(), 'admin', now(), 0);";
				String newHotSql = MessageFormat.format(hot_sql, count--, souId, "TYPE_MOVIE", FileOP.getUUID());
				String typeSql = MessageFormat.format(order_sql, np++, souId, "Movie_Boutique", FileOP.getUUID());

				sb.append(sql).append("\r\n");
				sb1.append(newHotSql).append("\r\n");
				sb2.append(typeSql).append("\r\n");

				f.renameTo(new File(f.getParent() + "/" + newName));				
			}
		}

		FileOP.writeFile(sqlPath, sb.toString() + sb1.toString() + sb2.toString(), "gb2312");

	}

}
